package com.ruoyi.framework.config;

import org.apache.http.HttpHost;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class SolrCloudConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(SolrCloudConfig.class);


    //solr集群地址（zk地址）
    @Value("${spring.data.solr.zk-host}")
    public  String ZK_HOST;

    //默认的collection
    @Value("${spring.data.solr.zk-core}")
    public String DEFAULT_COLLECTION;

    /**
     * 注入cloudSolrClient
     * @return
     */
    @Bean
    public CloudSolrClient solrClient() {
        CloudSolrClient client = new CloudSolrClient.Builder().withZkHost(ZK_HOST).build();
        client.setDefaultCollection(DEFAULT_COLLECTION);
        return client;
    }
}
